import React,{Component}from 'react';
import {NavigationContainer} from '@react-navigation/native';
import { createNativeStackNavigator } from '@react-navigation/native-stack';
import {Text,TouchableOpacity,Image} from 'react-native'
import TabPage from "./TabPage";
import LoginPage from "./LoginPage";
import WebviewPage from "./WebviewPage";
import ScanCodePage from "./ScanCodePage"
import RFIDPage from './RFID/RFIDPage';
import DefaultScanCodePage from './DefaultScanCodePage'
import { Images } from '../resource';
import {Toast, InputItem, Modal as AntdModal, portal,Button} from '@ant-design/react-native';
const Stack = createNativeStackNavigator();

export default class StackNavigator extends Component{


    constructor(props){
        super(props)
        this.state = {
            checkedUpgrade: true // 标记是否检查了更新，这里置为true则不会检查更新，设置为false则每次启动时检查更新，该功能默认不开启
        }
    }


    showConfirmDialog(navigation){

      AntdModal.alert('提示','确定要退出登录吗',[
        {
          text: '取消',
          onPress: () => console.log('cancel'),
          style: 'cancel',
        },
        { text: '确定', onPress: () =>{ navigation.replace('LoginPage')} },
      ])

     

    }

    // componentWillMount(){

    // }

    // componentDidMount(){

    // }

    render(){

        return(

            <NavigationContainer>
            <Stack.Navigator initialRouteName={"LoginPage"}>
              <Stack.Screen
                name="LoginPage"
                component={LoginPage}
                options={{title: '登录', headerShown: false}}
              />
             
             <Stack.Screen
                name="TabPage"
                component={TabPage}
                options={{title: '首页', headerShown: false}}
              />
      
            <Stack.Screen
                name="WebviewPage"
                component={WebviewPage}
                options={({route, navigation}) => ({
                  title: 'H5',
                  headerTitleAlign:'center',
                  headerTitleStyle:{
                    color: '#fff'
                  },
                  headerStyle:{
                    backgroundColor:'#0081cc'
                  }
                })}
              />

            <Stack.Screen
                name="DefaultScanCodePage"
                component={DefaultScanCodePage}
                options={({route, navigation}) => ({
                  title: '扫描',
                  headerTitleAlign:'center',
                  headerTitleStyle:{
                    color: '#fff'
                  },
                  headerBackImageSource: Images.ic_white_back,
                  headerStyle:{
                    backgroundColor:'#0081cc'
                  }
                })}
              />
            <Stack.Screen
                name="ScanCodePage"
                component={ScanCodePage}
                options={({route, navigation}) => ({
                  title: '扫描',
                  // headerShown: false,
                  headerTitleAlign:'center',
                  headerTitleStyle:{
                    color: '#fff'
                  },
                  headerBackImageSource: Images.ic_white_back,
                  headerStyle:{
                    backgroundColor:'#0081cc'
                  }
                })}
              />

            <Stack.Screen
                name="RFIDPage"
                component={RFIDPage}
                options={({route, navigation}) => ({
                  title: 'MES-RFID关联',
                  headerTitleAlign:'center',
                  headerTitleStyle:{
                    color: '#fff'
                  },
                  headerRight:() => (
                    <TouchableOpacity activeOpacity={0.5} onPress={() => this.showConfirmDialog(navigation)} >
                    <Image style = {{width:20, height: 20}} source={Images.ic_power_out} ></Image>
                  </TouchableOpacity>
                    
                  ),
                  headerBackImageSource: Images.ic_white_back,
                  headerStyle:{
                    backgroundColor:'#0081cc'
                  }
                })}
              />

      
            </Stack.Navigator>
          </NavigationContainer>
        );
       
    }
}